package com.htjc.integral.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
 

/**
 * 时间&日期服务
 */

public class DateService {

	/** 默认时间  */
	private static java.util.Date defaultDate = null;
	public static final int DATE_BY_MONTH =1; //按月分表
	public static final int DATE_BY_WEEK =2;	//按周分表
	public static final int DATE_BY_DAY =3;	//按天分表
	
//	private static Logger logger = Logger.getLogger(DateService.class);
	
	
	/**
	 * 获得当前时间，返回java.util.Date
	 * @return
	 */
	public static java.util.Date getCurrentUtilDate(){
		return Calendar.getInstance().getTime();
	}
	
	/**
	 * 获得当前时间，返回年份
	 * @return
	 */
	public static int getCurrentYear(){
		return Calendar.getInstance().get(Calendar.YEAR);
	}
	
	/**
	 * 获得当前时间的小时分钟和秒
	 * @return 返回一个数字8点半=83000，19点=190000
	 */
	public static int getCurrentHourMinuSec(){
		Calendar c = Calendar.getInstance();
		return c.get(Calendar.HOUR_OF_DAY) * 10000 + c.get(Calendar.MINUTE) * 100 + c.get(Calendar.SECOND);
	}
	
	/**
	 * 获得当月的第一天的00点00分00秒，返回java.util.Date
	 * @return
	 */
	public static java.util.Date getCurrentMonthFirstUtilDate(){
		Calendar c = Calendar.getInstance();
		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), 01, 00, 00, 00);
		return c.getTime();
	}
	
	/**
	 * 获得当天的00点00分00秒，返回java.util.Date
	 * @return
	 */
	public static java.util.Date getCurrentDayFirstUtilDate(){
		Calendar c = Calendar.getInstance();
		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), 00, 00, 00);
		return c.getTime();
	}
	
	/**
	 * 获得当天的23点59分59秒，返回java.util.Date
	 * @return
	 */
	public static java.util.Date getCurrentDayLastUtilDate(){
		Calendar c = Calendar.getInstance();
		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
		return c.getTime();
	}
	

	/**
	 * 获得当前时间的小时
	 * @return
	 */
	public static int getCurrentHour(){
		return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
	}
	
	/**
	 * 获得当前时间的分钟
	 * @return
	 */
	public static int getCurrentMin(){
		return Calendar.getInstance().get(Calendar.MINUTE);
	}
	
	/**
	 * 获得当前月份的最大天数
	 * @return
	 */
	public static int getCurrentMaxDayNum(){
		return Calendar.getInstance().getMaximum(Calendar.DAY_OF_MONTH);
	}
	/**获得当前是某天*/
	public static int getCurrentDay(){
		return Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
	}
	
	/**返回今天是星期几**/
	public static int getCurrentDayOfWeek(){
		
		return Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
	}
	
	/**返回今天是几月**/
	public static int getCurrentMonth(){
		return Calendar.getInstance().get(Calendar.MONTH);
	}
	
	/**
	 * 得到timer毫秒以后的时间
	 * @param timer
	 * @return
	 */
	public static java.util.Date getAfterUtilDate(long timer) {
		return new java.util.Date(getCurrentUtilDate().getTime() + timer);
	}
	
	public static java.util.Date getBeforeUtilDate(long timer) {
		return new java.util.Date(getCurrentUtilDate().getTime() - timer);
	}
	
	/**
	 * 获得默认时间(1970-01-01 00:00:00)
	 * @return
	 */
	public static java.util.Date getDefaultDate() {
		if (defaultDate == null) {
			Calendar c = Calendar.getInstance();
			c.set(1970, 01, 01, 00, 00, 00);
			defaultDate = c.getTime();
		}
		return defaultDate;
	}

	/**
	 * 获得当前时间，返回java.sql.Date
	 * @return
	 */
	public static java.sql.Date getCurrentSqlDate(){
		return new java.sql.Date(System.currentTimeMillis());
	}
	
	/**
	 * 获得当前时间，返回字符串(yyyy-MM-dd HH:mm:ss)
	 * @return
	 */
	public static String getCurrentDateAsString(){
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return formatter.format(getCurrentUtilDate());	
	}
	
	/**
	 * 获取当前时间，返回字符串(yyyy-MM-dd)
	 * @return
	 */
	public static String getCurrentDate2AsString(){
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		return formatter.format(getCurrentUtilDate());	
	}
	
	/**
	 * 获得当前时间，返回用户自定义格式字符串
	 * @param formatStr
	 * @return
	 */
	public static String getCurrentDateAsStringCustom(String formatStr){
		SimpleDateFormat formatter = new SimpleDateFormat(formatStr);
		return formatter.format(getCurrentUtilDate());	
	}
	
	/**
	 * 获得某个格式为 yyyy-MM-dd 的日期的 00:00:00 的时间
	 * @param dateStr
	 * @return
	 */
	public static Date getDateFirstTime(String dateStr){
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			return formatter.parse(dateStr+" 00:00:00");
		} catch (ParseException e) {
//			logger.error(ResourceBundleService.getString("txt.exception"), e);
		}
//		return getCurrentMonthFirstUtilDate();
		return getCurrentDayFirstUtilDate();
	}
	
	
	/**
	 * 获得某个格式为 yyyy-MM-dd 的日期的 23:59:59 的时间
	 * @param dateStr
	 * @return
	 */
	public static Date getDateLastTime(String dateStr){
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			return formatter.parse(dateStr+" 23:59:59");
		} catch (ParseException e) {
//			logger.error(ResourceBundleService.getString("txt.exception"), e);
		}
		return getCurrentDayLastUtilDate();
	}
	
	public static Date getDateByStrToTime(String dateStr) throws ParseException{
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return formatter.parse(dateStr);
	}
	
	/**
	 * 获得某个字符串的时间
	 * @param dateStr
	 * @return
	 */
	public static Date getDateByStrAndFormat(String dateStr, String formatStr){
		SimpleDateFormat formatter = new SimpleDateFormat(formatStr);
		try {
			return formatter.parse(dateStr);
		} catch (ParseException e) {
//			logger.error(ResourceBundleService.getString("txt.exception"), e);
		}
		return getCurrentUtilDate();
	}
	
	/**
	 * 将日期转换为字符串默认格式:yyyy-MM-dd HH:mm:ss)
	 * @param date
	 * @return
	 */
	public static String parseDateToString(java.util.Date date){
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return formatter.format(date);	
	}
	
	
	/**
	 * 将java.util.Date转化为HH:00格式的字符串
	 * @param date
	 * @return
	 */
	public static String parseDateToHourMinuteString(java.util.Date date) {
		SimpleDateFormat formatter = new SimpleDateFormat("HH:00");
		return formatter.format(date);	
	}
	
 
	
	/**
	 * 将字符串转换为日期java.sql.Date)
	 * @param dateStr
	 * @return
	 */
	public static java.sql.Date parseStringToSqlDate(String dateStr){
		return java.sql.Date.valueOf(dateStr);
	}
	
	/**
	 * 获得指定格式的日期对象
	 * @param date
	 * @param formatStr
	 * @return
	 */
	public static java.util.Date changeDateFormat(Date date, String formatStr) {
		SimpleDateFormat formatter = new SimpleDateFormat(formatStr);
		try {
			date =  formatter.parse(formatter.format(date));
		} catch (ParseException e) {
//			logger.error(ResourceBundleService.getString("txt.exception"), e);
		}
		
		return date;
	}
	
	/**
	 * 获得指定格式的日期的字符串
	 * @param date
	 * @param formatStr
	 * @return
	 */
	public static String getDateFormatStr(Date date, String formatStr) {
		SimpleDateFormat formatter = new SimpleDateFormat(formatStr);
		return formatter.format(date);
	}
	
	public static String getCurrentDayLastUtilDate1(){
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar c = Calendar.getInstance();
		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
		String time = formatter.format(c.getTime());
		return time;
	}
	
	public static String getDateFormatStr1(String time) {
		
		return time.substring(0,10);
	}
	
	/**
	 * 日期减少 - 减一天
	 * @param date
	 * @param days
	 * @return
	 */
    public static Date dateSubByDay(Date date)
    {

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DATE, -1);

        return cal.getTime();
    }
	
	
	 
	/**
	 * 日期增加-按日增加
	 * @param date
	 * @param days
	 * @return
	 */
    public static Date dateIncreaseByDay(Date date, int days)
    {

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DATE, days);

        return cal.getTime();
    }
    
    /**
	 * 日期增加-按分钟增加
	 * @param date
	 * @param days
	 * @return
	 */
    public static Date dateIncreaseByMinute(Date date, int minute){
    	Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MINUTE, minute);

        return cal.getTime();
    }
    
    /**
     * 日期增加-按秒增加
     * @param date
     * @param minute
     * @return
     */
    public static Date dateIncreaseBySecond(Date date, int second){
    	Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.SECOND, second);

        return cal.getTime();
    }
    
    
    /**距离当前时间天数,整数*/
    public static Integer distanceNowDay(Date dueDate){
    	int day=(int)((new Date().getTime()-dueDate.getTime())/(1000*60*60*24));
		return day;
	}
    
    /**距离当前时间天数，小数*/
    public static double distanceNowDayDouble(Date dueDate){
		 Date d1 = new Date();//当前时间
		 double l = (double)dueDate.getTime()-d1.getTime() ; 
		 double d = l/(24*60*60*1000);
		return d;
	}
    
    /**返回两个日期之间的的分钟数*/
    public static Integer MinuteBetween(Date earlyDay, Date lateDay){
    	int min=(int)((lateDay.getTime()-earlyDay.getTime())/(1000*60));
		return min;
    }
    
    /**获取当前月的第一天 00:00:00*/
    public static Date getCurrentMonthFirstDay(){
    	//java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");      
        GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();   
              gc.set(Calendar.DAY_OF_MONTH, 1);
              gc.set(Calendar.HOUR_OF_DAY, 0);
              gc.set(Calendar.MINUTE, 0);
              gc.set(Calendar.SECOND, 0);
        return gc.getTime();
    }
    
    /**距离当前时间秒数*/
    public static Integer distanceNowSecond(Date date){
    	int second=(int)((System.currentTimeMillis()-date.getTime())/1000L);
    	return second;
	}
    
    
    /**获取指定日期的月的第一天 00:00:00*/
    public static Date getMonthFirstDay(Date date){
    	 Calendar calendar = new GregorianCalendar();
    	 calendar.setTime(date);
    	 calendar.set(Calendar.DATE, 1);
    	 calendar.set(Calendar.HOUR_OF_DAY, 0);
    	 calendar.set(Calendar.MINUTE, 0);
    	 calendar.set(Calendar.SECOND, 0);
    	 return new Date(calendar.getTimeInMillis());
    }
    
    /**获取指定日期的月的最后一天59:59:59*/
    public static Date getMonthLastDay(Date date){
    	 Calendar calendar  =  new  GregorianCalendar();
    	 calendar.setTime(date);
    	 calendar.set( Calendar.DATE,  1 );
    	 calendar.roll(Calendar.DATE,  - 1 );
    	 calendar.set(Calendar.HOUR_OF_DAY, 23);
    	 calendar.set(Calendar.MINUTE, 59);
    	 calendar.set(Calendar.SECOND, 59);
    	 return new Date(calendar.getTimeInMillis());
    }
    
    
    //
    /**获取上个月的第一天 00:00:00*/
    public static Date getFirstDayOfLastMonth(){
    	//java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");      
        GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();   
              gc.set(Calendar.DAY_OF_MONTH, 1);
              gc.add(Calendar.MONTH, -1); 
              gc.set(Calendar.HOUR_OF_DAY, 0);
              gc.set(Calendar.MINUTE, 0);
              gc.set(Calendar.SECOND, 0);
        return gc.getTime();
    }
    
    /**获取上个月的最后一天 00:00:00*/
    public static Date getLastDayOfLastMonth(){
    	//java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");      
        GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();   
              gc.set(Calendar.DAY_OF_MONTH, 1);
              gc.add(Calendar.DATE, -1);
              gc.set(Calendar.HOUR_OF_DAY, 23);
              gc.set(Calendar.MINUTE, 59);
              gc.set(Calendar.SECOND, 59);
        return gc.getTime();
    }
    
    /**获取本月的最后一天 00:00:00*/
    public static Date getLastDayOfThisMonth(){
    	//java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");      
        GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();   
              gc.set(Calendar.DAY_OF_MONTH, 1);
              gc.add(Calendar.MONTH, 1);
              gc.add(Calendar.DATE, -1);
              gc.set(Calendar.HOUR_OF_DAY, 23);
              gc.set(Calendar.MINUTE, 59);
              gc.set(Calendar.SECOND, 59);
        return gc.getTime();
    }
    
    /**
     * 获得当前月的字符串格式yyyy-MM
     * @return
     */
    public static String getYearMonthStrOfThisMonth() {
    	return getDateFormatStr(getCurrentUtilDate(), "yyyy-MM");
    }
    
    /**返回两个日期之间的天数*/
    public static Long DayBetween(Date earlyDay, Date lateDay){
    	 SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
    	 Date d1;
		Date d2;
		long betweenDay=0;;
		try {
			 d1=ft.parse(ft.format(earlyDay));
			 d2=ft.parse(ft.format(lateDay));
			 betweenDay=(d2.getTime()-d1.getTime())/1000/60/60/24;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	//int day=(int)((lateDay.getTime()-earlyDay.getTime())/(1000*60*60*24));
		return betweenDay;
    }
    /**判断两日期是不是同一天*/
    public static boolean isSameDay(Date d1,Date d2){
    	SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    	if(formatter.format(d1).equals(formatter.format(d2))){
    		return true;
    	}else{
    		return false;
    	}
    	
    }
    
    /**
	 * 得到当前时间分钟的正点分钟后
	 * @param timer
	 * @return
	 */
	public static java.util.Date getMinuteAfterUtilDate(int minute) {
		 Calendar cal = Calendar.getInstance();
	     cal.setTime(getCurrentUtilDate());
	     cal.add(Calendar.MINUTE, minute);
	     cal.set(Calendar.SECOND, 0);
	     return cal.getTime();
	}
	
	 
	
	 
	
	/**
	 * 获得指定日期的00点00分00秒，返回java.util.Date
	 * @return
	 */
	public static java.util.Date getDayFirstUtilDate(Date date){
		Calendar c = Calendar.getInstance();
		c.setTime(date); 
		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), 00, 00, 00);
		return c.getTime();
	}
	
	/**
	 * 获得指定日期的23点59分59秒，返回java.util.Date
	 * @return
	 */
	public static java.util.Date getDayLastUtilDate(Date date){
		Calendar c = Calendar.getInstance();
		c.setTime(date); 
		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
		return c.getTime();
	}
	
	
	/** 日期加减后得到新的日期 unit: 5-天 3-周 2-月 1-年 */
	public static Date getNewDate(int unit,int offset){
		Date d=new Date();
		GregorianCalendar gc =new GregorianCalendar();
		gc.setTime(d);
		gc.add(unit,offset);
		return gc.getTime();
	}
	
	
	/**获取游戏当前天的开始时间，以5:30分割*/
	public static Date getGameCurrentDayFirstUtilDate(){
		Date nowTime = DateService.getCurrentUtilDate();
		Date dateStart = null;
		Calendar c = Calendar.getInstance();
		c.set(Calendar.HOUR_OF_DAY, 5);
		c.set(Calendar.MINUTE, 30);
		c.set(Calendar.SECOND, 0);
		if(nowTime.getTime()>c.getTimeInMillis()){//是否大于5:30
			dateStart = c.getTime();
		}else{
			c.set(Calendar.DAY_OF_YEAR,c.get(Calendar.DAY_OF_YEAR)-1);
			dateStart = c.getTime();
		}
		return dateStart;
	}
	
	/**获取游戏当前天的结束时间，以5:30分割*/
	public static Date getGameCurrentDayLastUtilDate(){
		Date nowTime = DateService.getCurrentUtilDate();
		Date dateEnd = null;
		Calendar c = Calendar.getInstance();
		c.set(Calendar.HOUR_OF_DAY, 5);
		c.set(Calendar.MINUTE, 30);
		c.set(Calendar.SECOND, 0);
		if(nowTime.getTime()>c.getTimeInMillis()){//是否大于5:30
			c.set(Calendar.DAY_OF_YEAR,c.get(Calendar.DAY_OF_YEAR)+1);
			dateEnd = c.getTime();
		}else{
			dateEnd = c.getTime();
		}
		return dateEnd;
	}
	
	
	/**
	 * 根据分表策略获取分表后缀
	 * @param type 分表策略
	 * @return
	 */
	public static String getTableSuffixByType(String tablePrefix,int type){
		Calendar c = Calendar.getInstance();
		String tableSuffix = "";
		
		if ( type == DATE_BY_MONTH ) {
			String strMonth = c.get( Calendar.MONTH ) +1 + "";
			if ( strMonth.length() == 1 ) strMonth = "0"+strMonth;
			
			tableSuffix =  tablePrefix+ "_" + c.get( Calendar.YEAR ) + "" + ( strMonth + "01");
			return tableSuffix;
		}
		else if ( type == DATE_BY_WEEK ) {
	    	int a = c.get(Calendar.DAY_OF_WEEK);
	    	c.add( Calendar.DATE, 2-a ); //本周的第一天
	    	String strMonth = c.get( Calendar.MONTH ) +1 + "";
			if ( strMonth.length() == 1 ) strMonth = "0"+strMonth;
			String strDay = c.get(Calendar.DAY_OF_MONTH) + "";
			if ( strDay.length() == 1 ) strDay = "0" + strDay;
	    	
			tableSuffix =  tablePrefix + "_" + c.get( Calendar.YEAR ) + "" + ( strMonth + strDay );
			return tableSuffix;
		}
		else if ( type == DATE_BY_DAY ) {
			String strMonth = c.get( Calendar.MONTH ) +1 + "";
			if ( strMonth.length() == 1 ) strMonth = "0"+strMonth;
			
			String daystr=c.get( Calendar.DAY_OF_MONTH )+"";
			if(daystr.length()==1)
				daystr = "0"+daystr;
				
			tableSuffix =  tablePrefix + "_" + c.get( Calendar.YEAR ) + "" + ( strMonth + daystr);
			return tableSuffix;
		}
		 
		return tableSuffix;
	}
	
	
	/**根据指定日期取定约定的表名后缀*/
	public static String getTableSuffixByTypeAndDate(String tablePrefix,int type,Date date){
		String tableSuffix = "";
		Calendar c = Calendar.getInstance();
		c.setTime(date); 
		if ( type == DATE_BY_MONTH ) {
			String strMonth = c.get( Calendar.MONTH ) +1 + "";
			if ( strMonth.length() == 1 ) strMonth = "0"+strMonth;
			
			tableSuffix =  tablePrefix + "_" + c.get( Calendar.YEAR ) + "" + ( strMonth + "01");
			return tableSuffix;
		}
		else if ( type == DATE_BY_WEEK ) {
	    	int a = c.get(Calendar.DAY_OF_WEEK);
	    	c.add( Calendar.DATE, 2-a ); //本周第一天，也就是 2-a天前！
	    	
	    	String strMonth = c.get( Calendar.MONTH ) +1 + "";
			if ( strMonth.length() == 1 ) strMonth = "0"+strMonth;
			String strDay = (c.get(Calendar.DAY_OF_MONTH)) + "";
			if ( strDay.length() == 1 ) strDay = "0" + strDay;
	    	
			tableSuffix =  tablePrefix + "_" + c.get( Calendar.YEAR ) + "" + ( strMonth + strDay );
			return tableSuffix;
		}
		else if ( type == DATE_BY_DAY ) {
			String strMonth = c.get( Calendar.MONTH ) +1 + "";
			if ( strMonth.length() == 1 ) strMonth = "0"+strMonth;
			String daystr=c.get( Calendar.DAY_OF_MONTH )+"";
			if(daystr.length()==1) daystr = "0"+daystr;
			
			tableSuffix =  tablePrefix + "_" + c.get( Calendar.YEAR ) + "" + ( strMonth + daystr);
			return tableSuffix;
		}
		 
		return tableSuffix;
	}
	
	
    
    public static void main(String[] args) {
    	
    	//String str = getDateFormatStr(getCurrentUtilDate(), "yyyy-MM");
    	//System.out.println("---"+getYearMonthStrOfThisMonth());
//    	Date d = getCurrentMonthFirstDay();
//    	java.text.SimpleDateFormat   df   =   new   java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//    	System.out.println(getFirstDayOfLastMonth());
//    	System.out.println( getTableSuffixByType(1) );

//    	System.out.println( getTableSuffixByType(2) );
//    	Calendar c = Calendar.getInstance();
//    	int a = c.get(Calendar.DAY_OF_WEEK);
//    	c.add( Calendar.DAY_OF_YEAR, 1-a );
//    	System.out.println( c.get( Calendar.DAY_OF_WEEK) );
//    	System.out.println( c.get(Calendar.MONTH) +"."+c.get(Calendar.));

//    	System.out.println( getTableSuffixByType(2) );
    	//Calendar now = Calendar.getInstance();
//    	int a = c.get(Calendar.DAY_OF_WEEK);
//    	c.add( Calendar.DAY_OF_YEAR, 1-a );
//    	System.out.println( c.get( Calendar.DAY_OF_WEEK) );
//    	System.out.println( (c.get(Calendar.MONTH)+1) +"."+(c.get(Calendar.DAY_OF_MONTH)+1));
//    	int a = now.get(Calendar.DAY_OF_WEEK);
//    	now.add( Calendar.DATE, 2-a ); //本周的第一天
//    	System.out.println( now.get(Calendar.MONTH)+","+a);
//    	System.out.println(getTableSuffixByTypeAndDate(2,new Date()));
//    	System.out.println("date before 10 days : " + (now.get(Calendar.MONTH) + 1) + "-"
//    	        + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR));
//    	
//    	Date d = getDayFirstUtilDate(new Date());
//    	System.out.println(d);
    	
    	Date d = DateService.getNewDate(2,-1);
    	System.out.println(d);
    	
    	
	}
    
    /**
	 * 得到timer毫秒以后的整分时间
	 * @param timer
	 * @return
	 */
	public static java.util.Date getAfterUtilDateMin(long timer) {
		return new java.util.Date(((getCurrentUtilDate().getTime() + timer)/60000)*60000);
	}
	/**获得日期自定义串*/
    public static String getTimeStrByDate(Date date){
    	String timeStr ="";
    	Calendar calendar = Calendar.getInstance();
    	calendar.setTime(date);
    	timeStr = calendar.get(Calendar.MONTH)+"月"+calendar.get(Calendar.DAY_OF_MONTH)+"日"
    	+calendar.get(Calendar.HOUR_OF_DAY)+":"+calendar.get(Calendar.MINUTE);
    	//timeStr =date.getMonth()+"月"+date.getDay()+"日" +date.getHours()+":"+date.getMinutes();
    	return timeStr;
    }
    
	
	/**
	 * 获得当前时间，返回字符串(yyyyMMddHHmmss)
	 * @return
	 */
	public static String getCurrentDateAsString3(){
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = getCurrentUtilDate();
		String dateStr = formatter.format(date);
		dateStr =dateStr.replace("-", "");
		dateStr =dateStr.replace(":", "");
		dateStr =dateStr.replace(" ", "");
		return dateStr;
	}
	/**获得日期自定义串*/
    public static String getTimeStr2ByDate(){
    	Date date = getCurrentUtilDate();
    	String timeStr ="";
    	Calendar calendar = Calendar.getInstance();
    	calendar.setTime(date);
    	timeStr = calendar.get(Calendar.YEAR)+calendar.get(Calendar.MONTH)+calendar.get(Calendar.DAY_OF_MONTH)
    	+calendar.get(Calendar.HOUR_OF_DAY)+calendar.get(Calendar.MINUTE)+"";
    	return timeStr;
    }
	/**
	 * 获得当前时间毫秒数
	 * @return
	 */
	public static String getCurrentDateMs(){
		
		Date date = getCurrentUtilDate();
		String dateStr = Long.toString(date.getTime()%1000);
		int zeroNum = dateStr.length()-3;
		while(zeroNum>0){
			dateStr="0"+dateStr;
			zeroNum--;
		}
		return dateStr;
	}
	
	/**
	 * 获取某个时间，返回字符串(yyyy-MM-dd)
	 * @return
	 */
	public static String getCurrentDate2AsStringByDate(Date date){
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		return formatter.format(date);	
	}
}
